//
//  MessageDetailViewController.m
//  PrintPort
//
//  Created by hy002 on 2018/1/3.
//  Copyright © 2018年 HUAYU. All rights reserved.
//

#import "MessageDetailViewController.h"

@interface MessageDetailViewController ()<UIWebViewDelegate>
{
    UIWebView *webView;
}

@end

@implementation MessageDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatUI];
}

- (void)creatUI
{
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"详情";
    UILabel *titLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 0, SCREEN_WIDTH-30*displaywidth, 40*displaywidth) Font:14.0 Text:_model.title Color:RGB(77, 77, 77)];
    titLab.lineBreakMode = NSLineBreakByTruncatingTail;
    [self.view addSubview:titLab];
    UILabel *timeLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 40*displaywidth, SCREEN_WIDTH-130*displaywidth, 25*displaywidth) Font:12.0 Text:_model.createDtm Color:RGB(128, 128, 128)];
    [self.view addSubview:timeLab];
    UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 69*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
    lineview.backgroundColor = LinesColor;
    [self.view addSubview:lineview];
    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 70*displaywidth, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-70*displaywidth)];
    webView.delegate = self;
    [webView loadHTMLString:_model.content baseURL:nil];
    [self.view addSubview:webView];
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *js= @"var script = document.createElement('script');"
    "script.type = 'text/javascript';"
    "script.text = \"function ResizeImages() { "
    "var myimg,oldwidth;"
    "var maxwidth = %f;"
    "for(i=0;i <document.images.length;i++){"
    "myimg = document.images[i];"
    "if(myimg.width > maxwidth){"
    "oldwidth = myimg.width;"
    "myimg.width = %f;"
    "}"
    "}"
    "}\";"
    "document.getElementsByTagName('head')[0].appendChild(script);";
    js=[NSString stringWithFormat:js,[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.width-15];
    [webView stringByEvaluatingJavaScriptFromString:js];
    [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
